#include <vector>
#include <iostream>
using namespace std;
class Solution
{
public:
    void solve(vector<vector<char>> &board)
    {
        int rows = board.size();
        int cols = rows ? board[0].size() : 0;
        vector<vector<bool>> visitedO(rows, vector<bool>(cols));
        for (int i = 0; i < rows; i++)
        {
            dfs(visitedO, board, i, 0, rows, cols);
            dfs(visitedO, board, i, cols - 1, rows, cols);
        }
        for (int i = 0; i < cols; i++)
        {
            dfs(visitedO, board, 0, i, rows, cols);
            dfs(visitedO, board, rows - 1, i, rows, cols);
        }
        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < cols; j++)
            {
                if (!visitedO[i][j])
                {
                    board[i][j] = 'X';
                }
            }
        }
    }
    void dfs(vector<vector<bool>> &visited, vector<vector<char>> &board, int x, int y, int rows, int cols)
    {
        if (x < 0 || x >= rows || y < 0 || y >= cols)
        {
            return;
        }
        if (visited[x][y])
        {
            return;
        }
        if (board[x][y] == 'X')
        {
            return;
        }
        visited[x][y] = true;
        dfs(visited, board, x - 1, y, rows, cols);
        dfs(visited, board, x + 1, y, rows, cols);
        dfs(visited, board, x, y - 1, rows, cols);
        dfs(visited, board, x, y + 1, rows, cols);
    }
};
